package com.xiaoq.matrix.minipro.endpoint;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.xiaoq.matrix.minipro.service.impl.MiniProServiceImpl;

import io.swagger.annotations.ApiParam;

@Controller
@RequestMapping("/api/v1/auth")
public class WeiXinController {
	
	@Autowired
	private  MiniProServiceImpl miniProService;
	
	@GetMapping("")
	private void autho(@RequestParam(value="userId",required=true)String userId,@RequestParam(value="type",required=true)@ApiParam(value="1代表公众号认证，2代表小程序认证")String type,HttpServletRequest request, HttpServletResponse response) throws IOException {
		//TODO 这里要不要做个用户正确性的判断
		String link = miniProService.generateLink(userId,type);
		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String message = "公众号";
		if("2".equals(type)){
			message = "小程序";
		}
		
		out.print("<!DOCTYPE html>\r\n" + 
				"<html lang=\"en\">\r\n" + 
				"<head>\r\n" + 
				"  <meta charset=\"utf-8\"/>\r\n" + 
				"  <meta name=\"viewport\" content=\"initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width\"/>\r\n" + 
				"  <meta content=\"yes\" name=\"apple-mobile-web-app-capable\">\r\n" + 
				"  <meta content=\"black\" name=\"apple-mobile-web-app-status-bar-style\">\r\n" + 
				"  <meta content=\"telephone=no\" name=\"format-detection\">\r\n" + 
				"  <meta content=\"email=no\" name=\"format-detection\" />\r\n" + 
				"  <title>Document</title>\r\n" + 
				"<style>\r\n" + 
				"/*去掉默认样式*/\r\n" + 
				"html, body, span, div, p, a, table, tbody, td, h1, h2, h3, h4, h5, h6, img, form, font, strong, b, i, dl, dt, dd, ol, ul, li, dl, dd, dt, iframe, label, blockquote, input, button,canvas {padding:0; margin:0;list-style: none;\r\n" + 
				"   box-sizing: border-box;\r\n" + 
				"   -webkit-text-size-adjust:none;\r\n" + 
				"}\r\n" + 
				"#page_dom{\r\n" + 
				"  display: flex;\r\n" + 
				"  justify-content: space-between;\r\n" + 
				"  padding: 40px 10px;\r\n" + 
				"}\r\n" + 
				".green_col{\r\n" + 
				"  color: #0ec369;\r\n" + 
				"  font-size: 18px;\r\n" + 
				"  margin-bottom: 11px;\r\n" + 
				"}\r\n" + 
				".line2{\r\n" + 
				"  color: #999;\r\n" + 
				"  margin-bottom: 19px;\r\n" + 
				"  font-size: 14px;\r\n" + 
				"}\r\n" + 
				".green_btn{\r\n" + 
				"  height: 50px;\r\n" + 
				"  width: 255px;\r\n" + 
				"  border-color: #0cb561;\r\n" + 
				"  font-size: 14px;\r\n" + 
				"  color: #fff;\r\n" + 
				"  background: url(http://p0sd9v5tn.bkt.clouddn.com/weixin.png) no-repeat 12px 10px;\r\n" + 
				"  background-color: #0ec369;\r\n" + 
				"  padding-left: 54px;\r\n" + 
				"  text-align: left;\r\n" + 
				"}\r\n" + 
				".right_title{\r\n" + 
				"  font-size: 16px;\r\n" + 
				"  color: #545454;\r\n" + 
				"  border-left: 2px solid #f99300;\r\n" + 
				"  line-height: 18px;\r\n" + 
				"  padding-left: 7px;\r\n" + 
				"  margin-bottom: 16px;\r\n" + 
				"}\r\n" + 
				".right_con{\r\n" + 
				"  font-size: 14px;\r\n" + 
				"  color: #999;\r\n" + 
				"}\r\n" + 
				"</style>\r\n" + 
				"</head>\r\n" + 
				"<body class=\"tourism_index_bg\" id=\"page_dom\">\r\n" + 
				"  <div class=\"left\">\r\n" + 
				"    <div class='green_col'>绑定微信"+message+",把店铺和微信打通</div>\r\n" + 
				"    <div class='line2'>绑定后即可在这里管理你的"+message+"，小Q提供比微信官方后台更强大的功能！</div>\r\n" + 
				"    <div><a href='"+link+"' target=_blank><button class=\"green_btn\">我有微信"+message+"，立即设置</button></a></div>\r\n" + 
				"  </div>\r\n" + 
				"  <div class=\"right\">\r\n" + 
				"    <div class=\"right_title\">温馨提示</div>\r\n" + 
				"    <div class=\"right_con\">一个微信"+message+"只能和一个店铺绑定</div>\r\n" + 
				"  </div>\r\n" + 
				"</body>");

	}

}
